package com.wbu.estatemanagement.controller;

import com.wbu.estatemanagement.common.MessageConstant;
import com.wbu.estatemanagement.common.Result;
import com.wbu.estatemanagement.common.StatusCode;
import com.wbu.estatemanagement.domain.Pet;
import com.wbu.estatemanagement.domain.User;
import com.wbu.estatemanagement.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("pet")
public class PetController {

    @Autowired
    PetService petService;


    @PostMapping("/userPet")
    public Result userPet(HttpSession httpSession){
        User user= (User) httpSession.getAttribute("user");

        Integer userId = user.getId();

        Pet pet=petService.findPet(userId);

        if (pet!=null){
            return new Result(true, StatusCode.OK, MessageConstant.PET_SUCCESS,pet);
        }
        return new Result(true, StatusCode.ERROR, MessageConstant.PET_FAIL);
    }
}
